﻿using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SelfService.Model.Models;
using SelfService.Services;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Mvc;

namespace SelfService.Controllers.Apis
{
    [AuthorizeJwtWithCookie]
    [ApiController]
    [ActionDescription("短信")]
    [Route("api/sms")]
    public class SmsController : BaseApiController
    {
        private readonly MessageSendService _service;

        public SmsController(MessageSendService service)
        {
            _service = service;
        }

        [HttpPost("Send")]
        public async Task<Result<string>> Send([FromBody]SmsSendRequest request)
        {
            var response = await _service.SendAndLog(request.Mobile, request.Content);
            return response;
        }
    }

    public class SmsSendRequest
    {
        [Required]
        public string Content { get; set; }

        [Required]
        public string Mobile { get; set; }
    }
}